
function debounce(func, wait) {
  let timeout;
  let count = 0;
  return function () {
    count+=2;
    const context = this;
    const args = arguments;
    clearTimeout(timeout);
    timeout = setTimeout(() => {
      func.apply(context, [...args, count]);
      count = 0;
    }, wait);
  };
}

const setInterval = (fn, s) => {
  let myReq;
  let an = () => {
    myReq = requestAnimationFrame(() => {
      if (new Date().getTime() - time >= s) {
        fn(myReq);
        time = new Date().getTime();
      }

      an();
    });
  };

  let time = new Date().getTime();
  myReq = an();
}


export {
  debounce,
  setInterval
}